// 页面里面可以直接调用getApp方法，拿到app实例
// 可以在实例里面去拿到全局的globalData的数据
const appInstance = getApp();

// 调用Page方法相当于注册页面
Page({
  data: {
    background: ['demo-text-1', 'demo-text-2', 'demo-text-3'],
    indicatorDots: true,
    vertical: false,
    autoplay: false,
    interval: 2000,
    duration: 500,
    msg: "hello 小程序!",
    url: "https://www.baidu.com/img/PCtm_d9c8750bed0b3c7d089fa7d55720d6cf.png",
    show: false,
    count: 10,
    name: appInstance.globalData.name
  },
  jump() {
    // 小程序一般都是用query进行传参
    wx.navigateTo({
        url: '../../packageA/pages/detail/detail',
    })
  },
  onLoad: function(options) {
    // "/xxx?a=3&b=4"  
    // onLoad是有一个options参数的，这个参数是可以获取到路由传递的信息的
    // Do some initialize when page load.
    console.log("onLoad", options);
  },
  onShow: function() {
    // Do something when page show.
    console.log("onShow");
  },
  onReady: function() {
    // Do something when page ready.
    console.log("onReady");
  },
  onHide: function() {
    // Do something when page hide.
    console.log("onHide");
  },
  onUnload: function() {
    // Do something when page close.
    console.log("onUnload");
  },
  // 页面下拉刷新时执行
  onPullDownRefresh: function() {
    console.log("onPullDownRefresh");
    // Do something when pull down.
  },
  // 页面上拉加载时执行
  onReachBottom: function() {
    // Do something when page reach bottom.
    console.log("onReachBottom");
  },
  onShareAppMessage: function () {
    // return custom share data when user share.
    console.log("onShareAppMessage");
  },
  onPageScroll: function() {
    // Do something when page scroll
    // console.log("onPageScroll");
  },
  onResize: function() {
    // Do something when page resize
    console.log("onResize");
  },
  onTabItemTap(item) {
    console.log(item.index)
    console.log(item.pagePath)
    console.log(item.text)
  },
  // Event handler.
  // 事件处理函数要写在和生命周期并列的位置
  fn() {
    //   需要使用this.setData来改变响应式数据
    // this.setData({
    //     count: this.data.count + 1
    // })

    // wx.getSystemInfo({
    //     success (res) {
    //       console.log(res.model)
    //       console.log(res.pixelRatio)
    //       console.log(res.windowWidth)
    //       console.log(res.windowHeight)
    //       console.log(res.language)
    //       console.log(res.version)
    //       console.log(res.platform)
    //     }
    //   })

    // wx.getLocation({
    //     type: 'wgs84',
    //     success (res) {
    //       const latitude = res.latitude
    //       const longitude = res.longitude
    //       const speed = res.speed
    //       const accuracy = res.accuracy
    //       console.log(res);
    //     }
    // })

    // wx.scanCode({
    //     success (res) {
    //       console.log(res)
    //     }
    //   })

    console.log(appInstance.globalData.name);
  }
})
